import { updateCompanyRectifyProblem, updateDeptRectifyProblem } from '@/api/rectify'
const ApiMixin = {
  props: ['assessType', 'rectify'],
  methods: {
    doUpdateRectify () {
      // 公用参数，每次请求都需要上传
      this.formData.problem_type = this.assessType
      this.formData.user_id = this.$store.state.authInfo.user.userid
      this.formData.user_name = this.$store.state.authInfo.user.username
      this.formData.user_dept = this.$route.query.bmmc != undefined ? this.$route.query.bmmc : this.$store.state.authInfo.rectifyDept.department_path
      this.formData.rectifyProblem = this.rectify

      // 判断调用接口
      let request = this.assessType === this.$vo.AssessType.CORP + '' ? updateCompanyRectifyProblem : updateDeptRectifyProblem
      console.log('formData', this.formData)
      request(this.formData).then(res => {
        let { data } = res
        if (data[this.$response.CODE] === this.$response.SUCCESS) {
          this.$toast.success('更新整改信息成功')
          this.$emit('onConfirm')
        } else {
          this.$toast.fail('更新整改信息失败：' + data[this.$response.MESSAGE])
        }
      }, errFunc => {
        this.$notify('服务调用失败：' + errFunc.toString())
        console.log(errFunc.toString())
      })
    }
  }
}

export default ApiMixin
